package bit.pja.wolfkill.Controller;


import bit.pja.wolfkill.RabbitMQ.Sender;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/rabbitMQ")
@Api(value = "RabbitMQ测试")
public class MQController {

    @Autowired
    Sender sender;

    @Autowired
    RabbitTemplate rabbitTemplate;  //使用RabbitTemplate,这提供了接收/发送等等方法

    @GetMapping("/direct")
    @ApiOperation("Direct模式")
    public String direct(String msg) {
        sender.send(msg);
        System.out.println(msg);

        return msg;
    }

    @GetMapping("/topic1")
    @ApiOperation("topic模式，关键词topic.man")
    public String topic1(String msg) {
        rabbitTemplate.convertAndSend("topicExchange", "topic.man", msg);
        return msg;
    }

    @GetMapping("/topic2")
    @ApiOperation("topic模式，关键词topic.woman")
    public String topic2(String msg) {
        rabbitTemplate.convertAndSend("topicExchange", "topic.woman", msg);
        return msg;
    }

    @GetMapping("/fanout1")
    @ApiOperation("fanout模式,fanout1")
    public String fanout1(String msg) {
        rabbitTemplate.convertAndSend("fanoutExchange_1",null, msg);
        return msg;
    }

    @GetMapping("/fanout2")
    @ApiOperation("fanout模式,fanout2")
    public String fanout2(String msg) {
        rabbitTemplate.convertAndSend("fanoutExchange_2",null, msg);
        return msg;
    }


}
